<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%
	String path = request.getContextPath() + "/";
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="css/bootstrap.css">
<title>朗读亭--管理员编辑</title>
<style>
tr {
	line-height: 10px;
	height: 25px;
}
</style>
</head>
<body>
	<div style="width:100%;margin-top:10px;">
		<div style="width:100%;margin-top:3px;">
			<form id="typeForm">
			<input type="hidden" name="id" id="id" value="${admin.id }" />
			<input type="hidden" name="passwd" id="passwd" value="${admin.passwd }" />
			<table style="width:100%;">
				<tr>
					<td class="text-right">账号：</td>
					<td><input type="text" <c:if test="${admin!=null }"> readonly="readonly"</c:if> name="account" id="account" value="${admin.account }"/></td>
				</tr>
				<c:if test="${admin==null }">
					<tr>
						<td class="text-right">密码：</td>
						<td><input type="password" name="password" id="password"/></td>
					</tr>
				</c:if>
				<tr>
					<td class="text-right">姓名：</td>
					<td><input type="text" name="name" id="name" value="${admin.name }"/></td>
				</tr>
				<tr>
					<td class="text-right">角色：</td>
					<td><select name="roleid" id="roleid">
						<option value="">请选择</option>
						<c:forEach var="role" items="${rlist}">
						<option value="${role.id }" <c:if test="${role.id==admin.roleid }">selected="selected"</c:if>>${role.name }</option>
						</c:forEach>
					</select></td>
				</tr>
				<tr>
					<td class="text-right">联系电话：</td>
					<td><input type="text" name="phone" id="phone" value="${admin.phone }"/></td>
				</tr>
				</table>
			</form>
		</div>
		<div style="text-align: center;">
			<div style="margin-top:20px;">
				<a class="btn btn-success" onclick="saveType();" >保存</a>
			</div>
		</div>
	</div>
	<script src="js/jquery-1.9.1.js"></script>
	<script src="js/md5.js"></script>
	<script type="text/javascript" src="js/layer/layer.js"></script>
	<script type="text/javascript">
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		function saveType(){
			if($("#account").val()==null || $("#account").val()==''){
				layer.msg("请输入帐号！");
				return;
			}
			var pd = '${admin.passwd}';
			if(pd==undefined || pd == ''){
				if($("#password").val()==null || $("#password").val()==''){
					layer.msg("请输入密码！");
					return;
				}
				$("#passwd").val(hex_md5($("#password").val()));
			}
			if($("#roleid").val()==null || $("#roleid").val()==''){
				layer.msg("请选择角色！");
				return;
			}
			$.ajax({
				async : false,
				cache : false,
				type : 'post',
				dataType : "json",
				data : $("#typeForm").serialize(),
				url : "admin/save_admin",// 请求的action路径
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					layer.msg("请求失败！");
				},
				success : function(data) {
					if(data.state=="9003"){
						layer.msg("没有权限！");
						return ;
					}else if(data.state=="9002"){
						layer.msg("请重新登录！");
						top.location.reload();
						return ;
					}
					if(data){
						parent.layer.close(index);
						parent.regetlist();
						layer.msg("保存成功！");
					}else{
						layer.msg("保存失败！");
					}
				}
			});	
		}
		
	</script>
</body>
</html>